unit wbDataset;

interface

uses
  Windows, System.SysUtils, System.Classes,
  DBClient, Provider,
  Oracle, OracleData;

type

  TwbDataset = class(TComponent)
  private
    FSQL: TStringList;
    FOracleDataset: TOracleDataset;
    FDatasetProvider: TDatasetProvider;
    FClientDataSet: TClientDataSet;
    FSession: TOracleSession;
    //function GetClientDataSet: TClientDataSet;
    //function GetDatasetProvider: TDatasetProvider;
    procedure SetSQL(const Value: TStringList);
    procedure SetSession(const Value: TOracleSession);
    //function GetOracleDataset: TOracleDataset;
    { Private declarations }
  protected
    { Protected declarations }
    procedure Loaded; override;
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    function ClientDataset: TClientDataSet;
  published
    { Published declarations }
    property Session: TOracleSession read FSession write SetSession;
    property SQL: TStringList read FSQL write SetSQL;
    //property DatasetProvider: TDatasetProvider read GetDatasetProvider;
    //property ClientDataSet: TClientDataSet read GetClientDataSet;
    property OracleDataset: TOracleDataset read FOracleDataset;
  end;

implementation

{ TSQLQuery2 }

function TwbDataset.ClientDataset: TClientDataSet;
begin
  FClientDataSet.Close;
  FClientDataSet.Open;

  Result := FClientDataSet;
end;

constructor TwbDataset.Create(AOwner: TComponent);
begin
  FSQL := TStringList.Create;

  inherited;


  FOracleDataset := TOracleDataset.Create(Self);
  FOracleDataset.Name := Self.Name + 'OracleDataset';
  FOracleDataset.Session := FSession;

  FClientDataSet := TClientDataSet.Create(Self);
  FClientDataSet.Name := Self.Name + 'Dataset';
  FClientDataSet.FetchOnDemand := True;
  // Include blobs with lengths <= MaxInt
  // IncludeBlobsInDelta(FClientDataSet, MaxInt);

  FDatasetProvider := TDatasetProvider.Create(Self);
  FDatasetProvider.Name := Self.Name + 'Provider';
  FDatasetProvider.Options := FDatasetProvider.Options + [poIncFieldProps];

  FClientDataSet.ProviderName := FDatasetProvider.Name;
  FDatasetProvider.DataSet := FOracleDataset;
end;

procedure TwbDataset.Loaded;
begin
  inherited;
  //FOracleDataset.SQL.Assign(FSQL);
  FOracleDataset.SQL.Text := FSQL.Text;
end;

destructor TwbDataset.Destroy;
begin
  FSQL.Free;
  FClientDataSet.Free;
  FDatasetProvider.Free;
  FOracleDataset.Free;
  inherited;
end;

{
function TwbDataset.GetClientDataSet: TClientDataSet;
begin
  Result := FClientDataSet;
end;

function TwbDataset.GetDatasetProvider: TDatasetProvider;
begin
  Result := FDatasetProvider;
end;



function TwbDataset.GetOracleDataset: TOracleDataset;
begin
  Result := FOracleDataset;
end;
}

procedure TwbDataset.SetSession(const Value: TOracleSession);
begin
  if Value <> FSession then
  begin
    FOracleDataset.Close;
    FClientDataSet.Close;
    FSession := Value;
    FOracleDataset.Session := FSession;
  end;
end;

procedure TwbDataset.SetSQL(const Value: TStringList);
begin
  if Value.Text <> FSQL.Text then
  begin
    FOracleDataset.Close;
    FOracleDataset.SQL.Assign(Value);
    FClientDataSet.Close;
    //FSQL.Assign(Value);
    FSQL.Text := Value.Text;
  end;
end;

end.
